import * as actionTypes from './constants'

import { getTopBanner, getHotRecommend, getNewAlbum } from '@/services/recommend'

const changeBannerAction = (res) => ({
  type: actionTypes.CHANGE_TOP_BNNAER,
  banners: res.banners
})

const changeHotRecommendAcction = (res) => ({
  type: actionTypes.CHANGE_HOT_RECOMMEND,
  list: res.result
})

const changeNewAlbumAction = (res) => ({
  type: actionTypes.CHANGE_NEW_ALBUM,
  data: res.albums
})

export const getBanner = () => {
  return dispatch => {
    getTopBanner().then(res => {
      dispatch(changeBannerAction(res));
    })
  }
}

export const getRecommend = () => {
  return dispatch => {
    getHotRecommend().then(res => {
      dispatch(changeHotRecommendAcction(res))
    })
  }
}

export const getAlbum = () => {
  return dispatch => {
    getNewAlbum().then(res => {
      dispatch(changeNewAlbumAction(res))
    })
  }
}

